<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<script>
    /*药品信息自动补全*/
    autoCompleteDrug("drugNameId");
    function autoCompleteDrug(inputId){
        var url="${ctx}/drug/drugDict/autoComplete?drugCode=${drugInfo.drugDict.drugCode}";
        autoComplete(inputId,url,
            function(data){
                var rows = [];
                for(var i=0; i<data.length; i++){
                    rows[rows.length] = {
                        data:data[i],
                        value:data[i].id,
                        result:data[i].drugName
                    };
                }
                return rows;
            },function(data, i, max){
                return data.drugCode+"|"+data.drugName+"|"+data.drugSpec;
            },function(event,data,formatted){
                $('#drugId').attr('value',data.id);
                $('#minSpec').attr('value',data.drugSpec);
                $('#minUnits').attr('value',data.unit);
                $("#minUnitsName option[value='"+data.unit+"']").attr("selected", true);
                $('#minUnitsName').change();
            });
    }

    /*药品厂商补全*/
    autoCompleteFirm("supplierName");
    function autoCompleteFirm(inputId){
        var url="${ctx}/drug/drugSupplierCata/autoComplete?supplierClass=0";
        autoComplete(inputId,url,
            function(data){
                var rows = [];
                for(var i=0; i<data.length; i++){
                    rows[rows.length] = {
                        data:data[i],
                        value:data[i].id,
                        result:data[i].supplierName
                    };
                }
                return rows;
            },function(data, i, max){
                return data.inputCode+"|"+data.supplierName;
            },function(event,data,formatted){
                $('#drugSupplierCataId').attr('value',data.id);
            });
    }

    function funPackSpec(numId,minId,specId){
        var num = $.trim($("#"+numId).val());
        var min = $.trim($("#"+minId).val());
        if (num!=1&&num!='1'){
            $("#"+specId).val(min+"*"+num);
        }else {
            $("#"+specId).val(min);
        }
    }
    if("${drugInfo.minUnits}"!=''){
        minUnitsName(${drugInfo.minUnits});
    }
    function minUnitsName(minUnits){
        $('#minUnits').attr('value',minUnits);
        $("#minUnitsName option[value="+minUnits+"]").attr("selected", true);
        $('#minUnitsName').change();
    }
</script>
<div class="content-wrap">
        <div class="wrapper" style="bottom: 50px;">
            <ul class="nav nav-tabs">
                <li>
                    <a href="#"  onclick="loadDiv('rigthCenterDiv','${ctx}/drug/drugInfo/index?drugDict.drugCode=${drugInfo.drugDict.drugCode}')">药品基本信息列表</a>
                </li>
                <li class="active">
                    <a href="#" onclick="loadDiv('rigthCenterDiv','${ctx}/drug/drugInfo/form?drugDict.drugCode=${drugInfo.drugDict.drugCode}')">
                        <c:choose>
                            <c:when test="${drugInfo.id==''|| drugInfo.id==null}">
                                药品基本信息添加
                            </c:when>
                            <c:otherwise>药品基本信息修改</c:otherwise>
                        </c:choose>
                    </a>
                </li>
            </ul>
            <section class="panel panel-default">
                <div class="panel-body">
                    <div class="col-lg-12">
                        <form:form id="inputForm" data-parsley-validate="" modelAttribute="drugInfo" onsubmit="return formSaveLoad('rigthCenterDiv','inputForm','${ctx}/drug/drugInfo/save','${ctx}/drug/drugInfo/index?drugDict.drugCode=${drugInfo.drugDict.drugCode}');" method="post" class="form-horizontal">
                            <form:hidden path="id"/>
                            <form:hidden path="drugDict.id" id="drugId"/>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">药品名称：</label>
                                    <div class="col-sm-4">
                                        <form:input path="drugDict.drugName" id="drugNameId" htmlEscape="false" class="form-control"  maxlength="64" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">药品代码：</label>
                                    <div class="col-sm-4">
                                        <form:input path="drugDict.drugCode" id="drugCode" htmlEscape="false" class="form-control"  maxlength="64" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">包装数量：</label>
                                    <div class="col-sm-4">
                                        <form:input path="packageNum" id="packageNum" htmlEscape="false" class="form-control" data-parsley-required="true" data-parsley-type="number" maxlength="11" onblur="return funPackSpec('packageNum','minSpec','packageSpec')"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">包装规格：</label>
                                    <div class="col-sm-4">
                                        <form:input path="packageSpec" id="packageSpec" htmlEscape="false" readonly="true" data-parsley-required="true" class="form-control"  maxlength="20" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">包装单位：</label>
                                    <div class="col-sm-4">
                                        <form:select path="packageUnit" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('SPEC_UNIT')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                        </form:select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">药品厂商：</label>
                                    <div class="col-sm-4">
                                        <form:hidden path="drugSupplierCata.id" id="drugSupplierCataId"/>
                                        <form:input path="drugSupplierCata.supplierName" id="supplierName" htmlEscape="false" class="form-control"  maxlength="64" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">最小单位规格：</label>
                                    <div class="col-sm-4">
                                        <form:input path="minSpec" id="minSpec" htmlEscape="false" class="form-control" readonly="true" data-parsley-required="true" maxlength="20" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">最小单位：</label>
                                    <div class="col-sm-4">
                                        <input name="minUnits" id="minUnits" type="hidden" />
                                        <form:select path="minUnitsName" id="minUnitsName" class="form-control" data-parsley-required="true" disabled="true">
                                            <form:option value="" label="" />
                                            <form:options items="${fns:getDictList('SPEC_UNIT')}" itemLabel="label" itemValue="value" htmlEscape="false" />
                                        </form:select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">批准文号：</label>
                                    <div class="col-sm-4">
                                        <form:input path="passNo" htmlEscape="false" class="form-control"  maxlength="30" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">GMP标识</label>
                                    <div class="col-sm-4">
                                        <form:select path="gmp" class="form-control" data-parsley-required="true">
                                            <form:option value="" label=""/>
                                            <form:options items="${fns:getDictList('YES_NO')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
                                        </form:select>
                                    </div>
                                </div>
                                <%--<div class="form-group">--%>
                                    <%--<label class="col-sm-2 control-label">价格类型：</label>--%>
                                    <%--<div class="col-sm-4">--%>
                                        <%--<form:select path="drugClass" class="form-control" data-parsley-required="true">--%>
                                            <%--<form:option value="" label=""/>--%>
                                            <%--<form:options items="${fns:getDictList('TENDER_PRICE_CLASS')}" itemLabel="label" itemValue="value" htmlEscape="false"/>--%>
                                        <%--</form:select>--%>
                                    <%--</div>--%>
                                <%--</div>--%>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">备注信息：</label>
                                    <div class="col-sm-4">
                                        <form:textarea path="remarks" htmlEscape="false" class="form-control"  maxlength="1000"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-10">
                                        <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存">&nbsp;
                                        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="loadDiv('rigthCenterDiv','${ctx}/drug/drugInfo/index?drugDict.drugCode=${drugInfo.drugDict.drugCode}')">
                                </div>
                            </div>
                        </form:form>
                    </div>

                </div>
            </section>
        </div>
    </div>